package com.ogilvy.cms.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ogilvy.cms.bean.CmsDictionary;
import com.ogilvy.cms.bean.CmsRole;
import com.ogilvy.cms.dao.CmsDictionaryDao;
import com.ogilvy.cms.service.CmsDictionaryService;
import com.ogilvy.frame.service.BaseServiceImpl;

@Service
public class CmsDictionaryServiceImpl extends BaseServiceImpl implements CmsDictionaryService {
	@Autowired
	protected CmsDictionaryDao cmsDictionaryDao;
	//实现新增
	public CmsDictionary add(CmsDictionary cmsDictionary) {
		CmsDictionary cmsdictionary = cmsDictionaryDao.save(cmsDictionary);
		return cmsdictionary;
	}
	//实现删除
	public boolean del(Integer cmdId) {
		cmsDictionaryDao.deleteById(cmdId);
		return true;
	}
	//实现修改
	public boolean modify(CmsDictionary cmsDictionary) {
		cmsDictionaryDao.update(cmsDictionary);
		return true;		
	}
	//实现查询
	public List<CmsDictionary> query(CmsDictionary cmsDictionary) {
		if(!isEmpty(cmsDictionary.getCmdName())){
			return cmsDictionaryDao.findByProperty("cmdName", cmsDictionary.getCmdName().replace("'", ""));
		}
		if(!isEmpty(cmsDictionary.getParentCmdId()))
		{
			return cmsDictionaryDao.findByProperty("parentCmdId", cmsDictionary.getParentCmdId());
		}
		return cmsDictionaryDao.findAll();
	}
	//通过ID进行查询
	public CmsDictionary get(Integer cmdId){
		return cmsDictionaryDao.get(cmdId);
	}
	
	 /**根据筛选条件查询相关信息*/
	public List<CmsDictionary> queryByScreen(Map<String, String> screenMap) {
		return cmsDictionaryDao.getListByScreen(screenMap);
	}

}
